//
//  ECOrderAddBottomToolView.m
//  ECERP.CRM
//
//  Created by 刘思麟 on 2018/11/18.
//  Copyright © 2018 Mac. All rights reserved.
//

#import "ECOrderAddBottomToolView.h"

@interface ECOrderAddBottomToolView()

@property (nonatomic,strong) UIButton * addBT;

@property (nonatomic,strong) UIButton * submitBT;

@property (nonatomic,strong) UILabel * sumLB;

@end

@implementation ECOrderAddBottomToolView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.backgroundColor = ECCOLOR(0xffffff);
    WS(weakSelf, self);
    self.submitBT = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:self.submitBT];
    [self.submitBT setBackgroundImage:[UIImage imageWithColor:ECCOLOR_NAVIBACK] forState:UIControlStateNormal];
    [self.submitBT setTitle:@"提交 " forState:UIControlStateNormal];
    [self.submitBT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.mas_equalTo(weakSelf);
        make.width.mas_equalTo(118 * PX_RELATIVE375);
    }];
    [self.submitBT addTarget:self action:@selector(doSubmit:) forControlEvents:UIControlEventTouchUpInside];
    
    self.addBT = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.addBT setImage:[UIImage imageNamed:@"tab_btn_dingdanxinzeng_disable"] forState:UIControlStateNormal];
    [self.addBT setTitle:@"" forState:UIControlStateNormal];
    [self addSubview:self.addBT];
    [self.addBT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf).mas_offset(17 * PX_RELATIVE375);
        make.top.mas_equalTo(weakSelf.top).mas_offset(-27 * PX_RELATIVE375);
        make.width.height.mas_equalTo(54 * PX_RELATIVE375);
    }];
    [self.addBT addTarget:self action:@selector(doAddShop:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel * desLB = [[UILabel alloc] init];
    desLB.text = @"添加商品";
    desLB.font = ECFONT(12 * PX_RELATIVE375);
    desLB.textColor = ECCOLOR(0x666666);
    [self addSubview:desLB];
    [desLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(weakSelf.addBT);
        make.top.mas_equalTo(weakSelf.addBT.mas_bottom);
    }];
    
    UILabel * tipLB = [UILabel new];
    tipLB.textColor = ECCOLOR(0x333333);
    tipLB.font = ECFONT(15 * PX_RELATIVE375);
    tipLB.text = @"预订金额:";
    [self addSubview:tipLB];
    [tipLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.addBT.mas_right).mas_offset(22 * PX_RELATIVE375);
        make.top.mas_equalTo(weakSelf).mas_offset(6 * PX_RELATIVE375);
    }];
    
    WS(weakTipLB, tipLB);
    self.sumLB = [UILabel new];
    self.sumLB.textColor = ECCOLOR(0xFF3C32);
    self.sumLB.font = ECFONT(15 * PX_RELATIVE375);
    self.sumLB.text = @"¥6600";
    [self addSubview:self.sumLB];
    [self.sumLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakTipLB);
        make.top.mas_equalTo(weakTipLB.mas_bottom);
        make.right.mas_lessThanOrEqualTo(weakSelf.submitBT.mas_left).mas_offset(-10 * PX_RELATIVE375);
    }];
    
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    if (!self.hidden) {
        CGPoint p = [self convertPoint:point toView:self.addBT];
        if (CGRectContainsPoint(self.addBT.bounds, p)) {
            return self.addBT;
        }
    }
    return [super hitTest:point withEvent:event];
}

- (void)doAddShop:(UIButton*)sender {
    if (self.doAddBlock) {
        self.doAddBlock();
    }
}

- (void)doSubmit:(UIButton *)sender {
    if (self.doSubmitBlock) {
        self.doSubmitBlock();
    }
}

@end
